package blue.squares;

import android.util.Log;
import android.graphics.Point;

import java.util.ArrayList;
import java.util.Random;

/**
 * A collection of utility functions.
 *
 * @author Luisa Lu
 */
public class Util {
    public static float squareF(float x) {
        return x * x;
    }

    public static float sqDistF(Point a, Point b) {
        return Util.squareF(a.x - b.x) + Util.squareF(a.y - b.y);
    }

    public static void logInfo(Object o, String msg){
        Class clazz = o.getClass();
        String name = clazz.getSimpleName();
        if(name == null || name.trim().length() == 0)
            name = clazz.getName();
        Log.i(clazz.getPackage().getName(), name+"."+msg);
    }

    public static void logDebug(Object o, String msg){
        Class clazz = o.getClass();
        String name = clazz.getSimpleName();
        if(name == null || name.trim().length() == 0)
            name = clazz.getName();
        Log.d(clazz.getPackage().getName(), name+"."+msg);
    }

    public static void logVerbose(Object o, String msg){
        Class clazz = o.getClass();
        String name = clazz.getSimpleName();
        if(name == null || name.trim().length() == 0)
            name = clazz.getName();
        Log.v(clazz.getPackage().getName(), name+"."+msg);        
    }
    
    public static void permuteRandomly(ArrayList list){
        Random rand = new Random();
        for(int i = list.size()-1 ; i > 1; i--){
            int j = rand.nextInt(i-1);
            Object a = list.get(i);
            Object b = list.get(j);
            list.set(j, a);
            list.set(i, b);
         }
    }
}
